package com.dreamfire.display.display3D
{
	import flash.display.Sprite;
	import flash.display.Stage;
	import flash.display.Stage3D;
	import flash.display3D.Context3D;
	import flash.events.Event;

	public class Viewport3D extends Sprite
	{
		private var _stage:Stage;
		private var _stage3D:Stage3D;
		private var _context3D:Context3D;
		
		public function Viewport3D(stage:Stage)
		{
			_stage = stage;
			_stage3D = _stage.stage3Ds[0];
			_stage3D.addEventListener(Event.CONTEXT3D_CREATE, onContext3DCreate);
			_stage3D.requestContext3D();
		}
		
		public function render(event:Event = null):void
		{
			
		}
		
		private function onContext3DCreate(event:Event):void
		{
			if(_stage.hasEventListener(Event.ENTER_FRAME))
				_stage.removeEventListener(Event.ENTER_FRAME, render);
			
			_context3D = _stage3D.context3D;
			if(_context3D == null)
			{
				throw new Error("-Stage3D上下文环境创建失败！");
			}else{
				trace("-加速方式：" + _context3D.driverInfo);
			}
		}
	}
}